package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.entity.Login;
import com.example.mapper.LoginMapper;
import com.example.result.PageResult;
import com.example.service.ILoginService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.utils.BaseException;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 陈昌吉
 * @since 2024-04-16
 */
@Service
public class LoginServiceImpl extends ServiceImpl<LoginMapper, Login> implements ILoginService {

    /**
     * 登录
     */
    @Autowired
    private LoginMapper loginMapper;
    @Override
    public Login login(Login login) {
        Login user = loginMapper.getUser(login);
        if (user==null){
            throw new BaseException("账号或密码错误",401);
        }
        return user;
    }

    @Override
    public List<Login> getAll() {
        List<Login> login=loginMapper.selectLogin();
        System.out.println(login);
        return login;
    }

    @Override
    public List<Login> addlogin(Login login) {
//        System.out.println("当前login纹"+login);
        loginMapper.add(login);
        return null;
    }

    @Override
    public PageResult getLogin(Login login) {
        PageHelper.startPage(login.getPageIndex(),login.getPageSize());
        Page<Login> page=loginMapper.seleectgetLogin(login);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public List<Login> searchLogin(String name) {
        //System.out.println(login.getName().getClass().toString());
        List<Login> search = loginMapper.searchs(name);
        System.out.println("xx"+search);
        return search;
    }


}
